#include "modules/buffer_mgr.h"
#include "types/common.h"

int main()
{
	string  s1 = ("tb1");
	string  s2 = ("tb2");
	string  s3 = ("tb3");
	string  s4 = ("tb4");

	string s5 = "print buffer";
	string s6 = "print hit rate";
	BufferManager::initialize(3);

	BufferManager &bm = BufferManager::inst();

	int i;

	unsigned char record1[] = {1,2,3};
	unsigned char record2[] = {4,5,6};
//	unsigned char record3[] = {8,8};
//	unsigned char record4[] = {9,9};
//	unsigned char record5[] = {10,11,12};

	unsigned char block0[48];
	unsigned char block1[48];
	unsigned char block2[48];
	unsigned char block3[48];


	bm.create_table(s1);
	bm.create_table(s2);
	bm.create_table(s3);

	bm.write_block(s1, 0, record1);
	bm.write_block(s1, 0, record1);
	bm.write_block(s1, 0, record1);
	bm.write_block(s1, 0, record1);

	bm.write_block(s1, 1, record1);
	bm.write_block(s1, 1, record1);
	bm.write_block(s1, 1, record1);
	bm.write_block(s1, 1, record1);
	
	bm.write_block(s2, 0, record2);
	bm.write_block(s2, 0, record2);
	bm.write_block(s2, 0, record2);
	bm.write_block(s2, 0, record2);

	bm.write_block(s2, 1, record1);
	bm.write_block(s2, 1, record1);
	bm.write_block(s2, 1, record1);
	bm.write_block(s2, 1, record1);

	//Read records

   bm.read_block(s1,0,block0);
   bm.read_block(s1,1,block1);

   bm.read_block(s2,0,block2);
   bm.read_block(s2,1,block3);

   //Dump records

   printf("\nTable: t1, Block 0:\n");
   for(i = 0; i < 48; i++)
	   printf("%x",block0[i]);

   printf("\nTable: t1, Block 2:\n");
   for(i = 0; i < 48; i++)
	   printf("%x",block1[i]);

   printf("\nTable: t1, Block 0:\n");
   for(i = 0; i < 48; i++)
	   printf("%x",block2[i]);

   printf("\nTable: t1, Block 0:\n");
   for(i = 0; i < 48; i++)
	   printf("%x",block3[i]);

   //Print Buffer
	bm.print(s5);
	bm.print(s6);

	BufferManager::deinitialize();
	return 0;
}
